
#region Imports

using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;

#endregion

namespace Justa.Reflection
{
    /// <summary>
    /// 
    /// </summary>
    /// 
    /// <author>Abel Perez</author>
    /// 
    public class MethodInvocation
    {
        /// <summary>
        /// 
        /// </summary>
        /// 
        private object target;

        /// <summary>
        /// 
        /// </summary>
        /// 
        private MethodInfo method;

        /// <summary>
        /// 
        /// </summary>
        /// 
        private object[] arguments;

        /// <summary>
        /// 
        /// </summary>
        /// 
        /// <param name="target"></param>
        /// <param name="method"></param>
        /// <param name="arguments"></param>
        /// 
        public MethodInvocation(object target, MethodInfo method, object[] arguments)
        {
            if (target == null)
            {
                throw new ArgumentException("Specified Target is null.");
            }

            if (method == null)
            {
                throw new ArgumentException("Specified Method is null.");
            }

            this.target = target;
            this.method = method;
            this.arguments = arguments;
        }

        /// <summary>
        /// 
        /// </summary>
        /// 
        /// <returns></returns>
        /// 
        public object Proceed()
        {
            return method.Invoke(target, arguments);
        }

        /// <summary>
        /// 
        /// </summary>
        /// 
        public object Target
        {
            get { return target; }
        }

        /// <summary>
        /// 
        /// </summary>
        /// 
        public object[] Arguments
        {
            get { return arguments; }
        }

        /// <summary>
        /// 
        /// </summary>
        /// 
        public MethodInfo Method
        {
            get { return method; }
        }

        /// <summary>
        /// 
        /// </summary>
        /// 
        public string MethodName
        {
            get { return method.Name; }
        }
    }
}
